﻿package _0_JFrame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 * 2011-5-31 21:44:12
 * @author Administrator
 * 演示全屏显示及全屏与非全屏的切换功能
 */
public class TJFrame {
    JFrame frame;
    Container contentPane;
    JButton bun;
    public TJFrame(){
        frame=new JFrame("窗口测试");
        frame.setSize(400,400);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        contentPane=frame.getContentPane();
        bun=new JButton("全屏");
        bun.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        frame.dispose();
                        bun.setText(frame.isUndecorated()?"全屏":"退出全屏");
                        frame.setUndecorated(!frame.isUndecorated());
                        frame.setLocation(0, 0);
                        if(frame.isUndecorated()){
                            frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
                        }else{
                            frame.setSize(400, 400);
                            frame.setLocationRelativeTo(null);
                        }
                        frame.setVisible(true);
                    }
                });
            }
        });
        contentPane.add(bun);
        frame.setVisible(true);
    }
    public static void main(String args[]){
        new TJFrame();
    }
}
